import 'package:flutter/material.dart';
import 'package:banquanjie_app/app/services/screenAdapter.dart';
class LetterList extends StatelessWidget {
  final Map<String, dynamic> item;
  const LetterList({
    super.key,
    required this.item,
  });
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: ScreenAdapter.height(4)),
      width: ScreenAdapter.width(348),
      decoration: BoxDecoration(
        gradient: LinearGradient(begin: Alignment.bottomCenter, end: Alignment.topCenter ,colors: [Color(0xFFFFFFFF), Color(0xFFF2FFFB)]),
        borderRadius: BorderRadius.circular(ScreenAdapter.width(8)),
      ),
      clipBehavior: Clip.antiAlias,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildInfoSection(),
          _buildOptionsSection(),
           
        ],
      ),
    );
  }
  Widget _buildInfoSection() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Padding(
          padding: EdgeInsets.only(top: ScreenAdapter.height(18), left: ScreenAdapter.width(20)),
          child: Row(
            children: [
              SizedBox(
                width: ScreenAdapter.width(100),
                child: AspectRatio(
                  aspectRatio: 5 / 9,
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(ScreenAdapter.width(8)),
                    child: Image.network(
                      item['coverOssUrl'].isNotEmpty ? item['coverOssUrl'] : 'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/letter_empty.png',
                      width: double.infinity,
                      height: double.infinity,
                      fit: BoxFit.cover,
                    ),
                  ),
                ),
              ),
              SizedBox(width: ScreenAdapter.width(12)),
              Expanded(
                flex: 1,
                child: Stack(
                  children: [
                    // Top icon
                    if (item['topFlag'] != null && item['topFlag'] == true)
                      Positioned(
                        left: 0,
                        top: 0,
                        child: RotatedBox(
                          quarterTurns: 90,
                          child: Image.network(
                            'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/top_icon.png',
                            width: ScreenAdapter.width(48),
                            height: ScreenAdapter.width(48),
                          )
                        ),
                      ),
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            if (item['userEntrustFlag'] == 1)
                              Container(
                                padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(6)),
                                margin: EdgeInsets.fromLTRB(0, 0, ScreenAdapter.width(14), 0),
                                height: ScreenAdapter.width(24),
                                decoration: BoxDecoration(
                                  color: Color(0xFFF0F2F5),
                                  borderRadius: BorderRadius.circular(ScreenAdapter.width(4))
                                ),
                                child: Text('自营', style: TextStyle(height: 1, fontSize: ScreenAdapter.fontSize(24), color: Color(0xFF000000)))
                              ),
                            Container(
                                height: ScreenAdapter.width(24),
                                padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(6)),
                                // margin: EdgeInsets.fromLTRB(0, ScreenAdapter.width(10), 0, ScreenAdapter.width(10)),
                                decoration: BoxDecoration(
                                  color: Color(0xFFF0F2F5),
                                  borderRadius: BorderRadius.circular(ScreenAdapter.width(4))
                                ),
                                child: Text(item['literaryLengthName'], style: TextStyle(height: 1, fontSize: ScreenAdapter.fontSize(24), color: Color(0xFF000000)))
                              )
                          ]
                        ),
                        Container(
                          alignment: Alignment.centerLeft,
                          margin: EdgeInsets.only(top: ScreenAdapter.width(10)),
                          height: ScreenAdapter.width(42),
                          child: Text(item['worksTitle'], overflow: TextOverflow.ellipsis, maxLines: 1, style: TextStyle(height: 1,fontSize: ScreenAdapter.fontSize(28), color: Color(0xFF000000),fontWeight: FontWeight.w500),)
                        ),
                        Container(
                          alignment: Alignment.centerLeft,
                          // padding: EdgeInsets.only(left: ScreenAdapter.width(14)),
                          height: ScreenAdapter.width(40),
                          child: RichText(
                            text: TextSpan(
                              style: TextStyle(fontSize: ScreenAdapter.fontSize(24), color: Color(0xFF000000)),
                              children: [
                                if (item['partYear'] != null)
                                  TextSpan(
                                    text: '${item['partYear']}年',
                                  ),
                                if (item['projectProgressName'] != null)
                                  TextSpan(
                                    text: ' | ${item['projectProgressName']}',
                                  )
                              ]

                            )
                          )
                        ),
                        if (item['worksTypeSecondName'] != null)
                          Container(
                            alignment: Alignment.centerLeft,
                            height: ScreenAdapter.width(40),
                            child: Text('${ item['worksTypeSecondName'].replaceAll('|', ' / ') }', style: TextStyle(height: 1, fontSize: ScreenAdapter.fontSize(24), color: Color(0xFF000000)))
                          )
                      ],
                    ),
                  ],
                )
              ),
            ]
          ),
        ),
        
        Container(
          padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(14)),
          margin: EdgeInsets.only(bottom: ScreenAdapter.height(18)),
          child: Text(item['worksDetail'] != null ? '${item['worksDetail']}': '暂未上传...',  maxLines: 2, overflow: TextOverflow.ellipsis, style: TextStyle(height: 1.6,fontSize: ScreenAdapter.fontSize(26), color: Color(0xFF000000)))
        )
      ],
    )
    ;
  }
  Widget _buildOptionsSection() {
    return Container(
      padding: EdgeInsets.only(left: ScreenAdapter.width(14)),
      height: ScreenAdapter.width(50),
      decoration: BoxDecoration(
        border: Border(top: BorderSide(color: Color(0xFFF4F7FC), width: ScreenAdapter.width(1)))
      ),
      child:  Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              ClipRRect(
                child: Image.network(
                  'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/rep_play_icon.png',
                  width: ScreenAdapter.width(14),
                  height: ScreenAdapter.width(14),
                )
              ),
              SizedBox(width: ScreenAdapter.width(12)),
              Text('${ item['viewNum'] }', style: TextStyle(fontSize: ScreenAdapter.fontSize(20), color: Color(0xFF000000))),
              SizedBox(width: ScreenAdapter.width(18)),
              ClipRRect(
                child: Image.network(
                  'https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/rep_collect_icon.png',
                  width: ScreenAdapter.width(14),
                  height: ScreenAdapter.width(14),
                )
              ),
              SizedBox(width: ScreenAdapter.width(12)),
              Text('${ item['collectNum'] }', style: TextStyle(fontSize: ScreenAdapter.fontSize(20), color: Color(0xFF000000))),
            ]
          ),
          if (item['worksTradeFlag'] == 0)
            Text(
              '仅展示',
              style: TextStyle(
                fontSize: ScreenAdapter.fontSize(20),
                color: Color(0xFF00B277),
              ),
            ),
          SizedBox(height: ScreenAdapter.height(14))
        ]
      )
    );
  }
}